
# 从src到dst，复制所有除了以.ets结尾的文件，但是.test.ets文件要复制
# 不复制.gitignore中忽略的文件

import sys
import os
import shutil

def migrate_common_part(src, dst):
    os.system(f"cd {src} && git ls-files > files.txt")
    os.makedirs(dst, exist_ok=True)
    with open('files.txt', 'r') as f:
        files = f.readlines()
    files2 = []
    for each in files:
        each = each.strip()
        if each.startswith('"'):
            each = each[1:-1]
        files2.append(each)
    files = files2
    print(f"Found {len(files)} files")
    files_copied = 0
    for file in files:
        try:
            if file.endswith('.ets') and not file.endswith('.test.ets'):
                continue
            else:
                os.makedirs(os.path.join(dst, file[:100
                ]), exist_ok=True)
                shutil.copy(file, os.path.join(dst, file))
                files_copied += 1
        except Exception as e:
            # print(f"Error copying {file}: {e}")
            pass
    print(f"Copied {files_copied} files")

if __name__ == "__main__":
    src = sys.argv[1]
    dst = sys.argv[2]
    migrate_common_part(src, dst)